#!/bin/bash -e

# summary coverage of depth in some region

function info() {
echo Usage: `basename $0` "[-c cut_tool] [-t dest] [-s sample_name] <in1.fq[.gz]> <in2.fq[.gz]> <in.bed>"
exit 65
}


while getopts  ":c:s:p:" opts
do
	case  $opts  in
	c) cut_tool=$OPTARG;;
	s) sample_name=$OPTARG;;
	p) out_prefix=$OPTARG;;
	t) dest=$OPTARG;;
	*) info;;
	esac
done
shift $(($OPTIND - 1))

if [ -z "$2" ]; then info; fi

. /mnt/ilustre/app/medical/tools/.var

if [ -z "$cut_tool" ]; then cut_tool=cutadp.sh; fi
if [ -z "$dest" ]; then dest=tes; fi


datee=`date +h%Hm%Ms%S_m%md%d_%y`
dir_name=${sample_name}_$datee
mkdir $dir_name
mv $log $dir_name
cd $dir_name

$cut_tool $1 $2

fastqc.sh -s$sample_name $1 $2 &

align2bam.sh -s $sample_name $out_prefix.1.cut.fastq $out_prefix.2.cut.fastq && rm $out_prefix.sam $out_prefix.1.cut.fastq $out_prefix.2.cut.fastq
 
summ.sh 1.sort.bam $3

bk.sh -t$dest *summary

wait

exit 0